package com.imooc.shop.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
@Slf4j
public class PerformanceMonitoring {
    private long start;
    private long end;

    @Pointcut("execution(* com.imooc.shop.service.ShopServiceImpl.login(..))")
    public void pointcut() {

    }

    @Before("pointcut()")
    public void before() {
        log.info("开始执行ShopServiceImpl的login方法");
    }

    @After("pointcut()")
    public void after() {
        log.info("ShopServiceImpl的login方法执行结束");
    }

    @Pointcut("execution(* com.imooc.shop.service.ShopServiceImpl.loadFirstArticleTypes(..))")
    public void pointcut1() {

    }

    @Before("pointcut1()")
    public void before1() {
        start = System.currentTimeMillis();
        log.info("开始执行ShopServiceImpl的loadFirstArticleTypes方法");
    }

    @After("pointcut1()")
    public void after1() {
        end = System.currentTimeMillis();
        log.info("ShopServiceImpl的loadFirstArticleTypes方法执行结束:耗时：" + (end - start));
    }
}
